package 创建型模式.工厂;

/**
 * @ClassNameElectricFactory
 * @Description
 * @Author
 * @Date2021/12/2 15:33
 **/
public class ElectricFactory {
    public static void main(String[] args) {
        AbstractElectricFactory haierFactory = new HaierFactory();
        AirConditioner ac = haierFactory.createAC();
        ac.show();


        AbstractElectricFactory tclFactory = new TCLFactory();
        Television tv = tclFactory.createTv();
        tv.show();
    }
}
// 抽象电器工厂
interface AbstractElectricFactory {
    public Television createTv();
    public AirConditioner createAC();
}

//抽象产品(电视)：提供了产品的接口
interface Television {
    public void show();
}
//抽象产品(空调)：提供了产品的接口
interface AirConditioner {
    public void show();
}

class HaierTelevision implements Television{

    @Override
    public void show() {
        System.out.println("海尔电视显示");
    }
}

class TCLTelevision implements Television{
    @Override
    public void show() {
        System.out.println("TCL电视显示");
    }
}
class HaierAirConditioner implements AirConditioner{

    @Override
    public void show() {
        System.out.println("海尔空调显示");
    }
}
class TCLAirConditioner implements AirConditioner{

    @Override
    public void show() {
        System.out.println("TCL空调显示");
    }
}


class HaierFactory implements AbstractElectricFactory{
    @Override
    public Television createTv() {
        System.out.println("海尔工厂生成");
        return new HaierTelevision();
    }

    @Override
    public AirConditioner createAC() {
        System.out.println("海尔工厂生成");
        return new HaierAirConditioner();
    }
}

class TCLFactory implements AbstractElectricFactory{
    @Override
    public Television createTv() {
        System.out.println("TCL工厂生成");
        return new TCLTelevision();
    }

    @Override
    public AirConditioner createAC() {
        System.out.println("TCL工厂生成");
        return new TCLAirConditioner();
    }
}